<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
		<meta HTTP-EQUIV="Pragma" CONTENT="no-cache"/> 
		<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache"/> 
		<meta HTTP-EQUIV="Expires" CONTENT="0"/>
		<title>Yagra个人中心</title>
		<link href="style/main.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="js/HttpRequest.js"></script>
		<script type="text/javascript" src="js/Connection.js"></script>
		<script language="javascript">
			 function logout(){
				var conn = new Ajax.Connection();
				var ret = conn.synGetString("yagra/logout.py", null);
				
				ret = ret.trim();
				
				if(ret === "success"){
					window.location.href = "login.html"
				}	
				else{
					alert("退出登录失败");
					window.location.href = "login.html"
				}
			}
			
			 function getBasePath() {
			     var curWwwPath = window.document.location.href;
			     var pathName = window.document.location.pathname;
			     var pos = curWwwPath.indexOf(pathName);
			     var localhostPaht = curWwwPath.substring(0, pos);
			     var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
			     return (localhostPaht + projectName);
			 }
			
			function loadUserInfo(){
				var conn = new Ajax.Connection();
				var ret = conn.synGetString("yagra/user_info.py", null);
				
				ret = ret.trim();
				
				try{
					user = eval("("+ret+")");
				}catch(e){
					user = null
				}
						
				if(!user || !user.username){
					alert(ret.substr(6));
					window.location.href = "login.html"
				}	
				else{
					document.getElementById("username").innerHTML = "欢迎 <span class='title'>"+user.username+"</span> 回来";
					document.getElementById("avatar").src = user.avatar+"&ran="+Math.random();
					document.getElementById("avatarURL").innerHTML = getBasePath()+"/yagra/avatar.py?username="+user.username;
				}
			}
			
			window.onload = loadUserInfo
		</script>
	</head>
	<body>
		<div>
			<div id="username"></div>
			<div>
				<span><a href="resetPassword.html" target="_blank">修改密码</a></span>
				<span><a onclick="logout()" href="#">退出登录</a></span>
			</div>
		</div>
		<br/>
		<div>
			<img id="avatar" style="height:120px;weight:80px" onerror="this.src='image/default.jpg'"/>
		</div>
		<div>
			图片访问链接：<span id="avatarURL">www.baidu.com</span>
		</div>
		<div id="uploadForm">
		<form enctype="multipart/form-data" action="yagra/upload.py" method="post">
			<div>
				<div style="padding:10px;">上传新头像，天天好心情：</div>
				<input style="margin-left:50px" type="file" name="file"/>
			</div>
			<div><input type="submit" value="上传"/></div>
		</form>
		</div>
	</body>
</html>